package com.financial.service.platbalancepay.controller;

import com.financial.service.platbalancepay.service.BalanceAgencyPayService;
import com.financial.service.platbalancepay.service.impl.BalancePayServiceImpl;
import com.financial.service.platbalancepay.utils.balanceutils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * describe: 余额代付接口
 *
 * @author zhaopengjun
 * @date 2019/8/30 10:45
 */
@RestController
@RequestMapping("/balanceAgencyPay")
public class BalanceAgencyPayController {
    public static final Logger logger = LoggerFactory.getLogger(BalancePayServiceImpl.class);
    @Autowired
    private BalanceAgencyPayService balanceAgencyPayService;
    @PostMapping("/ysAgencyPay")
    public String ysAgencyPay(@RequestParam Map<String,Object> requestMap){
        Map returnMap = new HashMap();
        try {
            Map<String, Object> map = balanceAgencyPayService.ysAgencyPay(requestMap);
            logger.info("调用余额代付结果集"+map);
            if (map.get("code").toString().equals("10000")&& map.get("trade_status").equals("TRADE_ACCEPT_SUCCESS")){
                returnMap.put("agentcyStatus",true);
            }else{
                returnMap.put("agentcyStatus",false);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("金融中心余额代付调用银盛代付接口失败 :{}",e.getMessage());
        }
        logger.info("调用余额代付结果返回优店"+returnMap);
        return JsonUtils.objectToJson(returnMap);
    }

    /**
     *  余额代付主动查询
     * @param requestMap
     * @return
     */
    @PostMapping("/paymentQuery")
    public Map<String,Object> paymentQuery(@RequestParam Map<String,Object> requestMap){

        return balanceAgencyPayService.paymentQuery(requestMap);
    }

}
